package com.sciencep.pro.admin.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sciencep.pro.admin.system.common.util.UserUtil;
import com.sciencep.pro.common.domain.QueryRequest;
import com.sciencep.pro.common.domain.ResponseResult;
import com.sciencep.pro.common.exception.CustomException;
import com.sciencep.pro.core.domain.dto.protypenode.ProTypeNodeTO;
import com.sciencep.pro.core.domain.dto.user.UserDetail;
import com.sciencep.pro.core.domain.vo.protypenode.ProTypeNodeVO;
import com.sciencep.pro.core.service.IProTypeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping(value = "/proTypeNode")
public class ProTypeNodeController {

    @Autowired
    private IProTypeService proTypeService;

    @Autowired
    private UserUtil userUtil;

    @GetMapping(value = "/getTypeNodeList")
    @ApiOperation(value = "查询开发类型及项目节点")
    public ResponseResult<Page<ProTypeNodeTO>> getTypeNodeList(QueryRequest queryRequest) {
        Page<ProTypeNodeTO> resultList = proTypeService.getTypeNodeList(queryRequest);
        return new ResponseResult<Page<ProTypeNodeTO>>().success(resultList);
    }

    @PostMapping(value = "/addTypeNode")
    @ApiOperation(value = "新增开发类型及项目节点")
    public ResponseResult<ProTypeNodeTO> addTypeNode(@RequestBody ProTypeNodeVO proTypeNodeVO) throws CustomException {
        UserDetail userDetail = userUtil.getCurrentUserDetail();
        return proTypeService.saveTypeNode(proTypeNodeVO, userDetail);
    }

    @DeleteMapping(value = "/deleteTypeNode")
    @ApiOperation("删除开发类型及项目节点")
    public ResponseResult<ProTypeNodeTO> deleteTypeNode(String typeId) throws CustomException {

        UserDetail userDetail = userUtil.getCurrentUserDetail();
        return proTypeService.deleteTypeNode(typeId, userDetail);
    }

    @PostMapping(value = "/updateTypeNode")
    @ApiOperation(value = "编辑开发项目及项目节点")
    public ResponseResult<ProTypeNodeTO> updateTypeNode(@RequestBody ProTypeNodeVO proTypeNodeVO) throws CustomException {
        UserDetail userDetail = userUtil.getCurrentUserDetail();
        return proTypeService.updateTypeNode(proTypeNodeVO, userDetail);
    }

}
